package com.metaera.app.utils;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.View;

import java.util.Objects;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;
import me.jessyan.autosize.utils.ScreenUtils;

public class ViewUtils {

    // @IntDef(value = {View.VISIBLE, View.GONE})
    public static void setVisibility(int visibility, View... views) {
        for (View view : views) {
            view.setVisibility(visibility);
        }
    }

    public static void addStatusBarHeightPadding(View view) {
        int statusBarHeight = ScreenUtils.getStatusBarHeight();
        int paddingTop = view.getPaddingTop();
        view.setPadding(
                view.getPaddingLeft(),
                paddingTop + statusBarHeight,
                view.getPaddingRight(),
                view.getPaddingBottom()
        );
    }

    public static Drawable getCompoundDrawable(@NonNull Resources resources, @DrawableRes int id) {
        Drawable drawableDeny = ResourcesCompat.getDrawable(resources, id, null);

        Objects.requireNonNull(drawableDeny).setBounds(
                0,
                0,
                drawableDeny.getMinimumWidth(),
                drawableDeny.getMinimumHeight()
        );

        return drawableDeny;
    }

}
